<template>
  <div class="app-container">
    <!--交往记录-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <label class="el-form-item-label">客户编号</label>
        {{ lianxirenval }}
        <label class="el-form-item-label">客户名称</label>
        {{ lkmCustName }}
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog :append-to-body="true" :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
          <el-form-item label="客户编号" prop="atvCustNo">
            <!--  <el-input v-model="form.atvCustNo" style="width: 370px;" /> -->
            {{ form.atvCustNo=lianxirenval }}
          </el-form-item>
          <el-form-item label="客户名称" prop="atvCustName">
            <!-- <el-input v-model="form.atvCustName" style="width: 370px;" /> -->
            {{ form.atvCustName=lkmCustName }}
          </el-form-item>
          <el-form-item label="时间	" prop="atvDate">
            <el-date-picker v-model="form.atvDate" type="datetime" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="地点" prop="atvPlace">
            <el-input v-model="form.atvPlace" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="概要	">
            <el-input v-model="form.atvTitle" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="详细信息">
            <el-input v-model="form.atvDesc" :rows="3" type="textarea" style="width: 370px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column prop="atvId" label="编号" />
        <el-table-column prop="atvCustNo" label="客户编号">
          <template slot-scope="scope">
            {{ scope.row.atvCustNo = lianxirenval }}
          </template>
        </el-table-column>
        <el-table-column prop="atvCustName" label="客户名称" />
        <el-table-column prop="atvDate" label="时间	" />
        <el-table-column prop="atvPlace" label="地点" />
        <el-table-column prop="atvTitle" label="概要	" />
        <el-table-column prop="atvDesc" label="详细信息" />
        <el-table-column v-if="checkPer(['admin','cstactity:edit','cstactity:del'])" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudCstactity from '@/api/cstactity.js'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'

const defaultForm = { atvId: null, atvCustNo: null, atvCustName: null, atvDate: null, atvPlace: null, atvTitle: null, atvDesc: null }
export default {
  name: 'Cstactity',
  components: { pagination, crudOperation, udOperation },

  mixins: [presenter(), header(), form(defaultForm), crud()],
  props: {
    lianxirenval: {
      type: String,
      default: ''
    },
    lkmCustName: {
      type: String,
      default: ''
    }
  },
  cruds() {
    return CRUD({ queryOnPresenterCreated: false, title: '客户交往记录', url: 'api/cstactity', idField: 'atvId', sort: 'atvId,desc', crudMethod: { ...crudCstactity }})
  },
  data() {
    return {
      permission: {
        add: ['admin', 'cstactity:add'],
        edit: ['admin', 'cstactity:edit'],
        del: ['admin', 'cstactity:del']
      },
      rules: {
        atvCustNo: [
          { required: true, message: '客户编号不能为空', trigger: 'blur' }
        ],
        atvCustName: [
          { required: true, message: '客户名称不能为空', trigger: 'blur' }
        ],
        atvDate: [
          { required: true, message: '时间	不能为空', trigger: 'blur' }
        ],
        atvPlace: [
          { required: true, message: '地点不能为空', trigger: 'blur' }
        ]
      },
      queryTypeOptions: [
        { key: 'atvCustNo', display_name: '客户编号' },
        { key: 'atvCustName', display_name: '客户名称' }
      ]
    }
  },
  watch: {
    'lianxirenval'() {
      this.crud.params = { atvCustNo: this.lianxirenval }
      this.crud.toQuery()
    }
  },
  created() {
    this.crud.params = { atvCustNo: this.lianxirenval }
    this.crud.toQuery()
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }
  }
}
</script>

<style scoped>

</style>
